package objects;

import java.awt.Graphics2D;
import map.Tile;
import engine.Game;

/**
 * A GameObject is any object in the game world. A creature, the player, an item, a cloud of fog...
 * anything that exists in the world and can be represented on a Tile.
 * 
 * @author Kyle_Solo
 */
public abstract class GameObject {
	private static int UID_MAX = 0;
	/**
	 * The tile this object currently occupies
	 */
	public Tile currentTile;
	/**
	 * nextTurn stores time when this object's next turn will take place. This is ignored if the
	 * object doesn't take turns.
	 */
	public long nextTurn = 0;

	private boolean playerControlled = true;
	/**
	 * This is a unique integer id for each GameObject, used to break ties in the time system
	 */
	public final int uid = UID_MAX++;

	protected boolean AI() {
		// TODO: implement AI someday
		return true;
	}

	/**
	 * @return true if the GameObject claims to be an item (mimics/traps could lie until you try to
	 *         actually pick them up)
	 */
	public boolean isItem() {
		return false;
	}

	protected boolean isPlayerComtrolled() {
		return playerControlled;
	}

	/**
	 * This event is triggered whenever a GameObject enters a tile.
	 * 
	 * @param tile
	 *            the tile that was entered
	 */
	public void onEnter(Tile tile) {}

	/**
	 * This event is triggered whenever a GameObject leaves a tile.
	 * 
	 * @param tile
	 *            the tile that was exited
	 */
	public void onExit(Tile tile) {}

	/**
	 * This event is triggered whenever a GameObject enters the tile this GameObject is on.
	 * 
	 * @param other
	 *            the GameObject that arrived
	 */
	public void onOtherEnter(GameObject other) {}

	/**
	 * This event is triggered whenever a GameObject leaves the tile this GameObject is on.
	 * 
	 * @param other
	 *            the GameObject that left
	 */
	public void onOtherExit(GameObject other) {}

	/**
	 * This event is triggered on this GameObject's turn.
	 * 
	 * @param game
	 * @return true if done with turn, false if not done
	 */
	public boolean onTurn(Game game) {
		return true;
	}

	/**
	 * Draw this GameObject at 0, 0
	 * 
	 * @param g2d
	 *            the graphics context to draw upon
	 */
	public abstract void render(Graphics2D g2d);

}
